package com.xcity.game.combat.skill.impl;

import java.util.List;

import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.skill.Skill;

/**
 * 重点保护<br/>
 * 为本方员工血量最少者恢复相当于自身血量{0}%的HP
 * @author yang.li
 *
 */
public class COMBAT_SKILL_90121 extends CombatSkill {

	public COMBAT_SKILL_90121(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		CombatUnit source = action.unit;
		List<CombatUnit> units = source.getTeam().all();
		CombatUnit theHpLeastUnit = null;
		for (int i = 0; i < units.size(); i++) {
			CombatUnit unit = units.get(i);
			if (!unit.isDied() && (theHpLeastUnit == null || unit.getHp() < theHpLeastUnit.getHp())) {
				theHpLeastUnit = unit;
			}
		}
		if (theHpLeastUnit != null) {
			ActionEffect eff = action.addTarget(theHpLeastUnit);
			theHpLeastUnit = eff.getUnit(); // 修正目标
			int val = (int) (theHpLeastUnit.getMaxHp() * skill.getParameter(0) / GameStaticConfig.percentBase);
			val = Math.max(val, 1);
			eff.effect(CombatAttributeType.HP, val);
		}
	}

}
